#include "AccountUtility.h"

std::string g_MakeAccount(const std::string& channelID, const std::string& userID)
{
    return channelID + userID;
}

bool g_MakeAccount(const std::string& channelID, const std::string& userID, char* account, size_t length)
{
    MMOLOG_ASSERT(account != nullptr);
	MMOLOG_ASSERT(length > 0);

    snprintf(account, length, "%s%s", channelID.c_str(), userID.c_str());
    account[length - 1] = '\0';

    return true;
}
//获取出生配置
const RoleBornCfgInfo *g_GetRoleBornCfg(uint8_t byProf, uint8_t bySex)
{
	const RoleBornCfgInfo *pRoleBornCfg = nullptr;
	const RoleBornCfgMap *pRoleCfgMap = g_GetRoleBornCfgTable()->GetRoleBornCfgMap();
	RoleBornCfgMap::const_iterator iter = pRoleCfgMap->begin();
	for (; iter != pRoleCfgMap->end(); ++iter)
	{
		const RoleBornCfgInfo &cfg = iter->second;
		if (cfg.professionID == byProf && cfg.gender == bySex)
		{
			pRoleBornCfg = &cfg;
			break;
		}
	}
	return pRoleBornCfg;
}

std::string g_MakeAccount(std::string& plamltStr, uint32_t channelId)
{
	char cNumber[32] = { 0 };
	snprintf(cNumber, sizeof(cNumber), "%d_", channelId);

	string newStr(cNumber);

	return newStr + plamltStr;
}

std::string g_MakeMd5(uint32_t uid, uint64_t timeStamp)
{
	char gameStr[512] = { 0 };

	snprintf(gameStr, sizeof(gameStr), "ADDX%d_%ld_%s", uid, timeStamp, "cgyx_loginaccount00102");
	string newStr(gameStr);

	return MD5(newStr).toStr();
}

std::string g_MakeConnectZoneMd5(uint32_t uid, uint64_t timeStamp)
{
	char gameStr[512] = { 0 };
	snprintf(gameStr, sizeof(gameStr), "CDDC%ld_%s", timeStamp, "conn9ectZone_cgyx0010");
	string newStr(gameStr);

	return MD5(newStr).toStr();
}


uint64_t g_MakeRoleDBCid(uint32_t zid, uint64_t count)
{
	if (zid > MAX_ZONE_COUNT)
	{
		LogErrFmtPrint(" g_MakeRoleDBCid, err, cid > 1024*8");
		return 0;
	}
	//64位  zid bit[64-50] bit[50] =0  cid bit[1-49] 
	return ((uint64_t)zid << 50) + count;
}

std::string g_TransToLower(std::string str)
{
	for (int i = 0; i < (int)str.length(); ++i)
	{
		if (str[i] >= 'A' && str[i] <= 'Z')
		{
			str[i] = str[i] + 32;
		}
		else
		{
			continue;
		}
	}
	//std::cout << str << std::endl;
	return str;
}
